<%@ page pageEncoding="UTF-8"%>

<%@ taglib uri="/tags/struts-tiles" prefix="tiles"%>
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<%@ taglib uri="/tags/struts-nested" prefix="nested"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix='fmt'%>

<style>
	.adinput {float:left; margin-left: 10px; }
</style>

<script>
	function after_switch(idx, op) {
		if (idx == 0 && op == 'allocate') {
			$("#btn_allocate").css("display", "");
		} else {
			$("#btn_allocate").css("display", "none");
		}
	}
	
	$(function(){
		$("#audit_post").unbind("click");
		$("#audit_post").click(function(){
			if ($("input[type=radio]").filter(":checked").size() == 0) {
				alertMsg.error("请选择审批状态...");
				return;
			} 
			
			$("#auditForm").submit();
		});
		
		$(".state_normal").unbind("click");
		$(".state_normal").click(function(){
			$("#return_to").css("display","none");
		});
		
		$(".state_return").unbind("click");
		$(".state_return").click(function(){
			$("#return_to").css("display","");
			//$("#return_to").combox();
		});
		
		$(".btn_cfrm").unbind("click");
		$(".btn_cfrm").click(function(){
			if ($(this).attr("id") == "proj_reject") {
				$("#decision").val("1");
			}
			alertMsg.confirm($(this).attr("title"), {
				okCall: function(){
					var current_panel = $.pdialog.getCurrent() && $.pdialog.getCurrent().filter(":visible").length > 0 ? $.pdialog.getCurrent() : navTab.getCurrentPanel();
					var form = current_panel.find("form");
					if (form) {
						form.submit();
					}
				}
			}); 
		});
		
		$("#processFormId").unbind("change");
		$("#processFormId").change(function(){
			var opt = $(this).find("option:selected");
			if (opt.hasClass("require_preaudit")) {
				$(".adinput").css("display", "inline");
				$("input[name='conferTime']").addClass("required");
			} else {
				$(".adinput").css("display", "none");
				$("input[name='conferTime']").removeClass("required");
			}
		});
		
	});
</script>

<!-- Body -->

<c:choose>
	<c:when test="${op ne null && op eq 'post_stuff'}">
		<form method="post" action="app/project/base.do?action=actionPostMaterail" class="pageForm required-validate" onsubmit="return validateCallback(this, dialogAjaxDone);">
	</c:when>
	<c:when test="${op ne null && op eq 'audit'}">
		<form method="post" action="app/project/audit.do?action=actionAuditProjectProcess" class="pageForm required-validate" onsubmit="return validateCallback(this, dialogAjaxDone);" id="auditForm">
	</c:when>
	<c:otherwise>
		<form method="post" action="app/project/checkin.do?action=actionSaveProject" class="pageForm required-validate" onsubmit="return validateCallback(this, dialogAjaxDone);">
	</c:otherwise>
</c:choose>
	<div class="unitBox" id="jbsxBox">
		<div class="pageContent">
			<!-- Tabs -->
			<div class="tabs" currentindex="${currentindex ne null ? currentindex : 0}" eventtype="click">
				<div class="tabsHeader">
					<div class="tabsHeaderContent">
						<ul>
							<li><a href="app/project/base.do?action=actionLoadProjectTab&pid=${pid}&tab=form&op=${op}<c:if test='${optype ne null}'>&optype=${optype}</c:if>" class="j-ajax" callback="after_switch(0,'${op}')"><span>详细信息</span></a></li>
							<li><a href="app/project/base.do?action=actionLoadProjectTab&pid=${pid}&tab=material&op=${op}" class="j-ajax" callback="after_switch(1,'${op}')"><span>材料区</span></a></li>
						</ul>
					</div>
				</div>
				<div class="tabsContent" style="height:auto;">
					<div inited="1000" style="display: none;"></div>
					<div inited="1000" style="display: block;"></div>
				</div>
				<div class="tabsFooter">
					<div class="tabsFooterContent"></div>
				</div>
			</div>
		</div>
		<div class="formBar">
			<ul>
				<c:if test="${op ne null && op eq 'post_stuff'}">
				<li>
					<label style="float:left; position: relative; top: 5px;">提交到：</label>
					<select class="combox" name="processFormId" id="processFormId" style="margin-right: 10px;">
						<logic:present name="entity" property="processForms">
							<logic:iterate name="entity" property="processForms" id="process">
								<c:if test="${process.auditState eq null}">
									<option value="${process.id}" class="${process.dependedFlow ne null ? 'require_preaudit' : ''}" ${entity ne null && entity.currentProcess ne null && entity.currentProcess.id eq process.id ? 'selected' : ''}>${process.nodeTitle}</option>	
								</c:if>
							</logic:iterate>
						</logic:present>
					</select>
					<label class="adinput" style="display: ${entity ne null && entity.currentProcess.dependedFlow ne null ? 'inline' : 'none'}">会议时间：<input type="text" class="textInput date ${entity ne null && entity.currentProcess.dependedFlow ne null ? 'required' : ''}" datefmt="yyyy-MM-dd HH:mm" style="width: 100px" name="conferTime" /></label>
					<label class="adinput" style="display: ${entity ne null && entity.currentProcess.dependedFlow ne null ? 'inline' : 'none'}">申请理由：<input type="text" class="textInput" value="" style="width: 100px" name="conferReason" /></label>
				</li>
				<li>
					<input type="hidden" name="projectId" value="${pid}" />
					<div class="buttonActive"><div class="buttonContent"><button type="submit">提交</button></div></div>
				</li>
				</c:if>
				
				<c:if test="${op ne null && op eq 'audit'}">
				<li style="margin-right: 20px">
					<label style="float:left; position: relative; top: 5px;">审核意见：</label>
					<input type="text" class="textInput" value="" style="width: 300px" name="auditComments" />
					<input type="radio" name="auditState" value="1" class="state_normal" />通过 
					<input type="radio" name="auditState" value="-1" class="state_return" />退回 
					<input type="radio" name="auditState" value="0" class="state_normal"/>否决
				</li>
				<li id="return_to" style="display:none">
					<label style="float:left; position: relative; top: 5px;">退回至材料提交的环节：</label>
					<select class="" name="returnProcessId" id="returnProcessId">
						<logic:present name="entity" property="processForms">
							<logic:iterate name="entity" property="processForms" id="process">
								<c:if test="${process.sequence le entity.currentProcess.sequence}">
									<option value="${process.id}" ${entity ne null && entity.currentProcess ne null && entity.currentProcess.id eq process.id ? 'selected' : ''}>${process.nodeTitle}</option>	
								</c:if>
							</logic:iterate>
						</logic:present>
					</select>
				</li>
				<li>
					<input type="hidden" name="projectId" value="${pid}" />
					<div class="buttonActive"><div class="buttonContent"><button type="button" id="audit_post">提交</button></div></div>
				</li>
				</c:if>
				
				<c:if test="${op ne null && op eq 'allocate' && optype eq null}">
				<li id="btn_allocate">
					<div class="buttonActive"><div class="buttonContent"><button type="button" class='btn_cfrm' id="proj_allocate" title="确定进行项目分配么？">项目分配</button></div></div>
					<div class="buttonActive"><div class="buttonContent"><button type="button" class='btn_cfrm' id="proj_reject" title="确定否决该项目么？">否决项目</button></div></div>
				</li>
				</c:if>
				
				<c:if test="${op ne null && op eq 'allocate' && optype ne null}">
				<li id="btn_reallocate">
					<div class="buttonActive"><div class="buttonContent"><button type="button" class='btn_cfrm' id="proj_allocate" title="确定项目重新分配么？">重新分配</button></div></div>
				</li>
				</c:if>
				
				<c:if test="${op ne null && op eq 'edit'}">
				<li id="btn_edit">
					<div class="buttonActive"><div class="buttonContent"><button type="button" class='btn_cfrm' id="proj_allocate" title="确定更新项目信息么？">更新项目</button></div></div>
				</li>
				</c:if>
				
				<c:if test="${op ne null && op eq 'view'}">
				<li>
					<div class="buttonActive"><div class="buttonContent"><button type="button" class="close">关闭</button></div></div>
				</li>
				</c:if>
				
				<input type="hidden" name="op" value="${op}" />
				<input type="hidden" id="decision" name="decision" value="" />
			</ul>
		</div>
	</div>
</form>